package apps

import (
	"gitee.com/zatto/project/tree/master/vblog/api/logger"
	"github.com/gin-gonic/gin"
)

var httpAppStore = map[string]HttpIocObject{}

type HttpIocObject interface {
	IocObject
	RegistryHandler(gin.IRouter)
}

func RegistryHttp(obj HttpIocObject) {
	// 判断对象是否注册
	if _, ok := httpAppStore[obj.Name()]; ok {
		panic(obj.Name() + " has registied")
	}

	// 存入appStore
	httpAppStore[obj.Name()] = obj

	// 打印日志
	logger.L().Debug().Msgf("http object %s registried", obj.Name())
}

func GetHttpApp(objName string) any {
	if v, ok := httpAppStore[objName]; ok {
		return v
	}
	panic("http object" + objName + " not found")
}
